package com.mj.listen1._08_红黑树;

import com.mj.listen1._08_红黑树.printer.BinaryTrees;
import com.mj.listen1._08_红黑树.tree.AVLTree;
import com.mj.listen1._08_红黑树.tree.RBTree;

public class Main {
    // 测试删除完全二叉树
    static void test10() {
        Integer[] integer = new Integer[]{
                56, 38, 89, 69, 12, 55, 93, 20, 18, 92, 61, 87, 51, 68, 49, 41, 26
        };

        AVLTree<Integer> tree = new AVLTree<>();
        for (int i = 0; i < integer.length; i++) {
            tree.add(integer[i]);
        }

        tree.remove(26);
        tree.remove(38);
        tree.remove(69);

        BinaryTrees.println(tree);
    }

    // 测试添加红黑树
    static void test2() {
        Integer[] integer = new Integer[]{
                56, 38, 89, 69, 12, 55, 93, 20, 18, 92, 61, 87, 51, 68, 49, 41, 26
        };

        RBTree<Integer> tree = new RBTree<>();
        for (int i = 0; i < integer.length; i++) {
            tree.add(integer[i]);
            System.out.println("【" + integer[i] + "】");
            // 把每次添加后的树结构也打印出来
            BinaryTrees.println(tree);
            System.out.println("------------------------------------");
        }

        // 删除操作
        tree.remove(26);
        tree.remove(38);
        tree.remove(69);


        BinaryTrees.println(tree);
    }

    public static void main(String[] args) {
//        test10();
        test2();
    }
}
